import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
import { LivelibService } from 'src/app/service/livelib.service';

@Component({
  selector: 'app-room-list-editor',
  templateUrl: './room-list-editor.component.html',
  styleUrls: ['../../editor.less']
})
export class RoomListEditorComponent implements OnInit {

  constructor(private livelibService: LivelibService,) { }
  @Output() onRemove = new EventEmitter(null)
  @Output() onSave = new EventEmitter(null)
  @Input() selectEl = {
    type: 'roomList',
    shield: []
  }
  roomList = []
  ngOnInit(): void {
    console.log(this.selectEl)
    this.livelibService.page({
      status: 0,
      pagesize: 10,
      pageindex: 1
    }).subscribe(result => {
      this.roomList = result["data"].items
      for (let item of this.roomList) {
        if (this.selectEl.shield.includes(item.id)) {
          item.isShow = false
        } else {
          item.isShow = true
        }
      }
    });
  }
  remove() {
    this.onRemove.emit()
  }
  ngModelChange(id, e) {
    if (e) {
      if (this.selectEl.shield.includes(id)) {
        for (let i = 0; i < this.selectEl.shield.length; i++) {
          if (id == this.selectEl.shield[i]) {
            this.selectEl.shield.splice(i, 1)
          }
        }
      }
    } else {
      if (!this.selectEl.shield.includes(id)) {
        this.selectEl.shield.push(id)
      }
    }
    this.onSave.emit()
  }
}
